#define _CRT_SECURE_NO_WARNINGS 1

#include <iostream>
#include <sstream>
using namespace std;

struct TreeNode {
    char val;
    TreeNode* left;
    TreeNode* right;
    TreeNode(char x) :val(x), left(nullptr), right(nullptr) {}
};

TreeNode* buildTree(string& preorder, int& index)
{
    if (index >= preorder.size() || preorder[index] == '#')
    {
        index++;
        return nullptr;
    }
    TreeNode* root = new TreeNode(preorder[index++]);
    root->left = buildTree(preorder, index);
    root->right = buildTree(preorder, index);
    return root;

}

void inorderTraversal(TreeNode* root)
{
    if (!root) return;
    inorderTraversal(root->left);
    cout << root->val << " ";
    inorderTraversal(root->right);

}

int main() {
    string line;
    while (cin >> line)
    {
        int index = 0;
        TreeNode* root = buildTree(line, index);
        inorderTraversal(root);
        cout << endl;
    }


}
